import {legacy_createStore,applyMiddleware} from "redux"
import logger from "redux-logger"
import thunk from "redux-thunk"
import {ALLSTATE,ALLACTION,GETLIST} from "../types/store.d"
const initialState = {
    listArr:JSON.parse(window.localStorage.getItem("listArr") as string)||[]
}

const reducer= (state:ALLSTATE = initialState, { type, payload }:ALLACTION) => {
  switch (type) {

  case GETLIST:
    let arr=[...state.listArr];
    arr=payload;
    state.listArr=arr;
    window.localStorage.setItem("listArr",JSON.stringify(state.listArr))
    return { ...state, ...payload }

  default:
    return state
  }
}
const store =legacy_createStore(reducer,applyMiddleware(thunk,logger));
export default store;
